// Vista

Application.Vista = Backbone.View.extend({
	inicia: function () {
		var self = this;

		_.bindAll(this, 'beforeRender', 'render', 'afterRender', 'cerrar');

		_.wrap(this.render, function (render) {
			self.beforeRender();
			render();
			self.afterRender();
		})();

	},
	beforeRender: function () {		
		if (Application.ultimaVista) {
			
			var vistaGuardada = Application.vistaGuardada[Application.ultimaVista];
			vistaGuardada.cerrar();
		}
		Application.ultimaVista = this.nombre;
	},
	render: function () {
		return this;
	},
	afterRender: function () {
	},
	cerrar: function () {
        if (this.onClose) {
			this.onClose();
		}
		this.undelegateEvents();
		this.$el.empty();
	}
});
